import express from "express"
import mountMethodDemo from "./routes/method.js"
import pathMethod from  "./routes/path.js"
import routerDemo from "./routes/router-demo.js"

const PORT = 3000
const app = express()

app.use((req,res,next)=>{
  const { method, path, query, body, headers } = req
  console.log(`[${method}] ${path}`)
  console.log('query:', query)
  console.log('headers:', headers)
  console.log('body:', body)
  next()
})
app.use(routerDemo)
app.use("/demo",routerDemo)
app.get(/hello/,(req,res)=>{
  res.send("<h1>Hello World</h1>")
})
app.get("/world/:id",(req,res)=>{
  const { params } = req
  console.log('params', params)
  res.json(params)
})
mountMethodDemo(app)
pathMethod(app)
app.listen(PORT,()=>{
  console.log(`Server is running at http://localhost:${PORT}`)
  
})